import 'package:elephant_fish/page/index_title_bo_page.dart';
import 'package:elephant_fish/page/index_title_di_page.dart';
import 'package:elephant_fish/page/index_title_huang_page.dart';
import 'package:elephant_fish/page/index_title_jun_page.dart';
import 'package:elephant_fish/page/index_title_pin_page.dart';
import 'package:elephant_fish/page/index_title_shen_page.dart';
import 'package:elephant_fish/page/index_title_wang_page.dart';
import 'package:elephant_fish/page/index_title_x_page.dart';
import 'package:elephant_fish/page/index_title_zhu_page.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class IndexTitlePage extends StatefulWidget {
  const IndexTitlePage({Key key}) : super(key: key);

  @override
  _IndexTitlePageState createState() => _IndexTitlePageState();
}
class _TabData {
  final Widget tab;
  final Widget body;
  _TabData({this.tab, this.body});
}

final _tabDataList = <_TabData>[
  _TabData(tab: Text('平民'), body: IndexTitlePinPage(categoryName: '平民',)),
  _TabData(tab: Text('子爵'), body: IndexTitleXPage(categoryName: '子爵',)),
  _TabData(tab: Text('伯爵'), body: IndexTitleBoPage(categoryName:'伯爵')),
  _TabData(tab: Text('亲王'), body: IndexTitleWangPage(categoryName: '亲王',)),
  _TabData(tab: Text('皇帝'), body: IndexTitleHuangPage(categoryName: '皇帝',)),
  _TabData(tab: Text('神'), body: IndexTitleShenPage(categoryName: '神',)),
  _TabData(tab: Text('大帝'), body: IndexTitleDiPage(categoryName: '大帝',)),
  _TabData(tab: Text('天君'), body: IndexTitleJunPage(categoryName: '天君',)),
  _TabData(tab: Text('造物主'), body: IndexTitleZhuPage(categoryName: '造物主',))
];

class _IndexTitlePageState extends State<IndexTitlePage> {
  final tabBarList = _tabDataList.map((item) => item.tab).toList();
  final tabBarViewList = _tabDataList.map((item) => item.body).toList();
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(length: tabBarList.length,
        child: Scaffold(
          backgroundColor: Color(0xff1b1b1b),
          appBar: AppBar(
            automaticallyImplyLeading: false,
            backgroundColor: Color(0xff1b1b1b),
            title: Row(
              children: [
                Expanded(child: TabBar(
                  // isScrollable: true, //可滚动
                  indicatorColor: Color(0xffe5d1b2), //指示器的颜色
                  labelColor: Color(0xffe5d1b2), //选中文字颜色
                  unselectedLabelColor: Color(0xfff3f3f3), //为选中文字颜色
                  isScrollable: true,
                  unselectedLabelStyle: TextStyle(
                    fontSize: SizeUtil.px(30),
                  ),
                  labelStyle: TextStyle(
                    fontSize: SizeUtil.px(30),
                  ),
                  // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
                  tabs: tabBarList,
                ),

                ),

              ],
            ),
          ),
          body:
          TabBarView(
              children: tabBarViewList
          ),
        ),);
  }
}
